#include "RSSParser.h"

RSSParser::RSSParser()
{
    this->FluxList = new std::list<FluxRSS*>();
    this->currFlux = NULL;
}

RSSParser::~RSSParser()
{
}

void	RSSParser::startElement(XMLNode* node)
{
    this->currNode = node->getNodeName();
    if (node->getNodeName() == "item")
        this->currFlux = new FluxRSS();
}

void	RSSParser::endElement(XMLNode* node)
{
    if (node->getNodeName() == "item")
    {
        this->FluxList->push_back(this->currFlux);
        this->currFlux = NULL;
    }
    this->currNode = "";
}

void	RSSParser::dataElement(std::string data)
{
    if (this->currFlux)
    {
        if (this->currNode == "title")
            this->currFlux->setTitle(data);
        else if (this->currNode == "link")
            this->currFlux->setLink(data);
        else if (this->currNode == "description")
            this->currFlux->setDescription(data);
        else if (this->currNode == "pubDate")
            this->currFlux->setPubDate(data);
    }
}

void	RSSParser::parseError(XMLException e)
{
}
